package models;


import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig.Feature;


/*
 * Use this class to define commands to send to the Main Display from the Android Tablets.
 */
@JsonTypeInfo(use=JsonTypeInfo.Id.MINIMAL_CLASS, include=JsonTypeInfo.As.PROPERTY)
public class Command {
	
	public enum CommandValue
	{
		Handshake,
		CloseConnection,
		TcardUpdate,
		TcardDelete,
		OpenTcard,
		CloseTcard,
		RetrieveAllTcards	
	}
	
	public static final ObjectMapper Mapper = new ObjectMapper();
	
	private CommandValue _command;
	private UUID _specificTcardId;
	private Collection<Tcard> _tcards;
	
	static {
		Mapper.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, false);
	}
	
	public Command(CommandValue command)
	{
		this(command, null, new ArrayList<Tcard>());
	}
	
	public Command(CommandValue command, UUID specificTcardId)
	{
		this(command, specificTcardId, new ArrayList<Tcard>());
	}
	
	public Command(CommandValue command, Collection<Tcard> tcards)
	{
		this(command, null, tcards);
	}
	
	@JsonCreator
	public Command( @JsonProperty("command")          CommandValue command, 
					@JsonProperty("specificTcardId")  UUID specificTcardId, 
					@JsonProperty("tcards")           Collection<Tcard> tcards)
	{
		_command = command;
		_specificTcardId = specificTcardId;		
		_tcards = tcards;
	}

	public CommandValue getCommand()
	{
		return _command;
	}
	
	public UUID getSpecificTcardId()
	{
		return _specificTcardId;
	}
	
	public Collection<Tcard> getTcards()
	{
		return _tcards;
	}

}
